package uk.ac.tees.aetoolkit;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

/**
 * This class is a launch activity for the AEToolkit which contains image
 * buttons that when clicked on take the user to their chosen application.
 * 
 * @author Sohail Rahman, Mark Williamson, Robert Sheffield
 */
public class HomeScreen extends Activity {

	/**
	 * Sets the context as the current activity.
	 */
	private Context context = this;

	/**
	 * Called when the activity is first created.
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_homescreen);
		// call setAppButtons method to map imageButtons to their activity.
		setAppButtons();
	}

	/**
	 * A method used to link ImageButtons to an android intent. For example
	 * clicking on the notes button will take the user to the Notes class.
	 */
	public void setAppButtons() {
		// Get references to inflated resources.
		ImageButton calcB = (ImageButton) findViewById(R.id.imageButton1);
		ImageButton alarmB = (ImageButton) findViewById(R.id.imageButton2);
		ImageButton weatherB = (ImageButton) findViewById(R.id.imageButton5);
		ImageButton notesB = (ImageButton) findViewById(R.id.imageButton4);
		// Add listeners to ImageButtons and handle the onClick events.
		calcB.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent i = new Intent(context, Calculator.class);
				startActivity(i);
			}
		});
		alarmB.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent i = new Intent(context, Alarm.class);
				startActivity(i);
			}
		});
		weatherB.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent i = new Intent(context, Weather.class);
				startActivity(i);
			}
		});
		notesB.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent i = new Intent(context, Memo.class);
				startActivity(i);
			}
		});
	}
}
